#include <stdio.h>
#include <stdlib.h>

/*书的题目，作者，数量*/

typedef struct 
{
	char title[50];
	char author[50];
	int num;
}Book;

/*读者名字，性别，年龄，编号*/

typedef struct 
{
	char name[50];
	char sex[50];
	int age;
	int num;
}Reader;

/*管理员的名字，性别，年龄，编号，工资*/
typedef struct 
{
	char name[50];
	char sex[50];
	int age;
	int num;
	int wage;
}Librarian;

/*借书的书名和时间*/
typedef struct 
{
	char name[50];
	double time[50];
}Borrow;

/*输入书的信息并且输入到文件里面*/
void InputB(Book book[], int x)
{
	int i;
			
	for(i=0; i<x; i++)
	{	
		scanf("%s", book[i].title);
		scanf("%s", book[i].author);
		scanf("%d", &book[i].num);
	}
	
	FILE *fp1;
    
	fp1=fopen("book.bin", "w");
	
	if(fp1 == NULL)
	{
		printf("输入错误");
		exit(1);
	}
	
	for(i=0; i<x; i++)
	{
		fwrite(&book[i], sizeof(Book), 1, fp1);
	}
	
	fclose(fp1);
}

/*输出书的信息*/
void OutputB(Book book[], int x)
{
    int i;
    
    for(i=0; i<x; i++)
    {
        printf("书名=%s\n", &book[i].title);
        printf("作者=%s\n", &book[i].author);
        printf("剩余数量=%d\n", &book[i].num);
    }
}

/*输入读者的信息*/
void InputR(Reader reader[], int x)
{
	int i;
		
	for(i=0; i<x; i++)
	{		
		scanf("%s%s%d%d", &reader[i].name, &reader[i].sex, &reader[i].age, &reader[i].num);
	}
	
	FILE *fp;
	
	char c;

	fp=fopen("D:test/reader.txt","r");

	while((c = fgetc(fp)) != EOF) 
	{
		putchar(c);
	}

    fclose(fp);

    putchar('\n');

    fp=fopen("D:/test/reader.txt","r");

	while((c = fgetc(fp)) != EOF) 
	{
		putchar(c);
	}
    
	fclose(fp);
}

/*输出读者的信息*/			
void OutputR(Reader reader[], int x)
{
    int i;
    
    for(i=0; i<x; i++)
    {
        printf("姓名为%s\n", &reader[i].name);
        printf("性别为%s\n", &reader[i].sex);
        printf("年龄为%d\n", &reader[i].age);
        printf("编号为%d\n", &reader[i].num);
    }
}

/*输入图书管理员的信息*/
void InputL(Librarian librarian[], int x)
{
	int i;
		
	for(i=0; i<x; i++)
	{		
		scanf("%s%s%d%d%d", &librarian[i].name, &librarian[i].sex, &librarian[i].age, &librarian[i].num, &librarian[i].wage);
	}
}

/*输出图书管理员的信息*/
void OutputL(Librarian librarian[], int x)
{
    int i;
    
    for(i=0; i<x; i++)
    {
        printf("姓名为%s\n", &librarian[i].name);
        printf("性别为%s\n", &librarian[i].sex);
        printf("年龄为%d\n", &librarian[i].age);
        printf("编号为%d\n", &librarian[i].num);
        printf("工资为%d\n", &librarian[i].wage);
    }
}

/*输入借书者和时间*/
void InputBo(Borrow borrow[], int x)
{
	int i;
	
	for(i=0; i<x; i++)
	{
		scanf("%s%d", &borrow[i].name, &borrow[i].time);
	}
}

/*输出者和时间*/
void OutputBo(Borrow borrow[], int x)
{
	int i;
	
	for(i=0; i<x; i++)
	{
		printf("这书让%d%s借走了", &borrow[i].name, &borrow[i].time);
	}
}